<template>
    <div class="container">
        <el-form :model="medicalRecord" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-input v-model="medicalRecord.ID" type="hidden"></el-input>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="病历号" prop="caseNumber">
                        <el-input v-model="medicalRecord.caseNumber" @change="getCheckApply"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="检查结果">
                        <el-input v-model="checkApply.result" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="主诉" prop="readme">
                        <el-input type="textarea" v-model="medicalRecord.readme"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="现病史" prop="present">
                        <el-input type="textarea" v-model="medicalRecord.present"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="现病治疗情况" prop="presentTreat">
                        <el-input type="textarea" v-model="medicalRecord.presentTreat"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="既往史" prop="history">
                        <el-input type="textarea" v-model="medicalRecord.history"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="过敏史" prop="allergy">
                        <el-input type="textarea" v-model="medicalRecord.allergy"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="体格检查" prop="physique">
                        <el-input type="textarea" v-model="medicalRecord.physique"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="检查建议" prop="proposal">
                        <el-input type="textarea" v-model="medicalRecord.proposal"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="注意事项" prop="careful">
                        <el-input type="textarea" v-model="medicalRecord.careful"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="检查结果" prop="checkResult">
                        <el-input type="textarea" v-model="medicalRecord.careful"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="诊断结果" prop="diagnosis">
                        <el-input type="textarea" v-model="medicalRecord.diagnosis"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="处理意见" prop="handling">
                        <el-input type="textarea" v-model="medicalRecord.handling"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    import {HOST} from '../../common/config'

    export default {
        name: "addMedicalRecord",
        data() {
            return {
                medicalRecord: {
                    ID:'',
                    caseNumber: '',
                    readme:'',
                    present:'',
                    presentTreat:'',
                    history:'',
                    allergy:'',
                    physique:'',
                    proposal:'',
                    careful:'',
                    checkResult:'',
                    diagnosis:'',
                    handling:''
                },
                checkApply: {},
                rules:{
                    caseNumber:[
                        {required:true,message:"请输入病历号", trigger: 'blur'}
                    ],
                    readme:[
                        {required:true,message:"请输入主诉", trigger: 'blur'}
                    ]
                }
            }
        },
        mounted:function(){
              let path=`${HOST}/medicalRecord/${this.$route.params.id}`;
              this.$ajax.get(path).then((res)=>{
                  this.medicalRecord=res.data;
                  this.getCheckApply();
              })

        },
        methods: {
            getCheckApply() {
                let path = `${HOST}/checkApply?caseNumber=${this.medicalRecord.caseNumber}`;
                this.$ajax.get(path).then((res) => {
                    this.checkApply = res.data;
                })
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let path=`${HOST}/medicalRecord/update`;
                        this.$ajax.post(path,this.medicalRecord).then((res)=>{
                            if(res.data===1){
                                this.$message.success("添加成功！");
                            }else{
                                this.$message.error("服务器异常！");
                            }
                        })
                    } else {
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    }
</script>

<style scoped>
    .container{
        margin-top: 60px;
    }
</style>